{renv} is a package management tool for R that helps you create isolated and reproducible R environments. It allows you to specify the exact versions of R packages that your project depends on, ensuring that your code runs consistently across different environments.
With {renv}, you can create a project-specific library of packages, which are separate from your global R library. This allows you to have different versions of packages for different projects and ensures that your project dependencies are self-contained. {renv} also provides tools for managing and resolving package dependencies, making it easier to collaborate with others and share your code.
To use {renv} in your projects, set up the project environment by running renv::init(). This command creates an renv.lock file, which specifies the exact versions of packages needed for the project. Other people can then replicate the environment by running renv::restore() using the renv.lock file.
Open the slides in a new tab here.
Download the slides as a new pdf here.
renv.lock file here.renv.lock file that’s already there with this new one.renv.lock file that’s already in your R project.In your R project, run renv::restore().
Install a new R package of your choice. (Not sure what to choose? Try one of these fun packages. For example, I did install.packages("hadley/emo").)
Create an R script and save it in your R project. Include some code that requires the package. For example:
Run renv::status() to make sure your project picked up the package as a dependency.
Run renv::snapshot() to record that package in your lockfile.
Open your lockfile and look for your new package. For example, mine now has:
"emo": {
"Package": "emo",
"Version": "0.0.0.9000",
"Source": "git",
"RemoteType": "git",
"RemoteUrl": "https://github.com/hadley/emo",
"RemoteHost": "api.github.com",
"RemoteUsername": "hadley",
"RemoteRepo": "emo",
"RemoteRef": "master",
"RemoteSha": "3f03b11491ce3d6fc5601e210927eff73bf8e350",
"Requirements": [
"R",
"assertthat",
"crayon",
"glue",
"lubridate",
"magrittr",
"purrr",
"rlang",
"stringr",
"utils"
],
"Hash": "eb32b8f0bb50621ad498f5d836b546a4"
},